home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2903 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.2 KB

  1. Path: in2.uu.net!interaccess!d146
  2. From: jap@interaccess.com (Jeff Pleimling)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Printing to LPT1 Printer from within program
  5. Followup-To: comp.os.msdos.programmer
  6. Date: Wed, 24 Jan 96 21:49:38 GMT
  7. Organization: none
  8. Message-ID: <4e69fe$8hh@nntp.interaccess.com>
  9. References: <4e5ee9$m28_001@pr.mcs.net>
  10. NNTP-Posting-Host: d146.w.interaccess.com
  11. X-Newsreader: News Xpress Version 1.0 Beta #4
  12.  
  13. In article <4e5ee9$m28_001@pr.mcs.net>,
  14.    mdp@mika-sys.com (Michael D. Perry) wrote:
  15. >I have just started taking a C programming class and am using Borland 
  16. >C++ v4.0 at home.  Both my teacher and I are stumped as to how to 
  17. >print to a LPT (Line Printer) device from within the program.
  18.  
  19. Printing (under any operating system) is outside of the scope of
  20. the C language and should be discussed on an operating system
  21. specific group (comp.os.msdos.programmer in this case).
  22.  
  23. >I have read the FAQ and there are some references to this but not 
  24. >enough that I can quite figure it out.  As near as I can figure you 
  25. >can use iostreams or fprintf() with the later appearing to be the 
  26. >simpler of the two.  With that, from what I have seen, one uses a 
  27. >filename of stdprn but I get an error message when compiling.  My 
  28. >guess is that there is a header file or a definition/declaration 
  29. >statement that needs to be referenced.
  30.  
  31. iostreams is C++, this is a C newsgroup.
  32.  
  33. stdprn is not a filename.  With most MS-DOS compilers, stdprn is
  34. a pre-opened file *handle* that points to the PRN device (which,
  35. in turn, usually points to LPT1).  It is used like any other open
  36. file handle (i.e. "fprintf(stdprn, "This goes to the printer\n" ).
  37. Also, even though it is called stdprn it is *anything* but standard
  38. (as some people moving from dos to UNIX,Mac,... have found out).
  39. See below for a better approach.
  40.  
  41. >I have looked at lots of materials on the Internet, quite a few books, 
  42. >and hours in the on-line help and manuals for Borland C++ without 
  43. >finding anything much about this.  So either I am incredibly stupid 
  44. >because the answer is so obvious that no one writes about it or it is 
  45. >a little more obscure and someone maybe should write it into an FAQ?
  46.  
  47. a) you're not stupid, just looking in the wrong place &
  48. b) the comp.os.msdos.programmer FAQ *probably* tells how, the
  49.    most I expect the comp.lang.c FAQ to say is that it depends on the OS
  50.    (even though I haven't looked).
  51.  
  52. A *much* better way (IMHO) is to open the printer port using fopen().
  53. That way you can make it user configurable (what if they have a serial
  54. printer hooked to COM1 that they want to print to instead of the 
  55. printer on LPT1, or even 'print' to a standard file). As an example:
  56.     {
  57.         FILE *printer_handle;
  58.         printer_handle = fopen("LPT1", "w");
  59.         if (printer_handle != NULL) {
  60.             fprintf(printer_handle, "This goes to the printer\n"
  61.             fclose(printer_handle);
  62.         }
  63.     }
  64. Substitute a variable for "LPT1" and it can print to LPT1, LPT2,
  65. COM1, COM2, a file, etc...
  66.  
  67. I've (hopefully) re-directed followups to comp.os.msdos.programmer
  68. where there will be *much* more help and this is on topic.
  69.  
  70.  
  71. Jeff
  72. --
  73. Jeff Pleimling | jap@interaccess.com
  74. "No, Pinky, there YOU are.  I am nowhere near that vincinity." the Brain
  75.